<template>
	<el-tree :data="treeData" :props="defaultProps" node-key="id" :default-expanded-keys="dfExpKeys" ref="tree" :indent="10" accordion @node-click="nodeClick" :default-expand-all="false" highlight-current :expand-on-click-node="false"></el-tree>
</template>
<script>
export default {
	data() {
		return {
			treeData: this.$store.state.checkItemsStore.treeData,
			defaultProps: {
				label: 'name',
                children: 'accountItems'
            },
            dfExpKeys: []
		}
	},
	watch: {
		treeData(newVal) {
			let expandNodeId = this.$store.state.checkItemsStore.expandNodeId;
			this.dfExpKeys = expandNodeId;
			this.$nextTick(() => {
				this.$refs.tree.setCurrentKey(expandNodeId[0]);			//设置高亮状态
			});
		}
	},
	methods: {
		nodeClick(row) {
			this.$store.commit('checkItemsStore/updateRow', row);
			this.$store.commit('checkItemsStore/updateExpandNodeId', row['id']);
			this.$store.commit('checkItemsStore/updateTableData', [row]);
		}
	},
	created() {
		this.$store.dispatch('checkItemsStore/getTreeData');
	}
}
</script>